﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MYSMRM.Dao.Base
{
    public interface IDao<T> where T : class
    {
        /// <summary>
        /// Get instance
        /// </summary>
        /// <param name="id">primary key</param>
        /// <returns>instance</returns>
        T Get(object id);

        /// <summary>
        /// Load instance
        /// </summary>
        /// <param name="id">primary key</param>
        /// <returns>instance</returns>
        T Load(object id);

        /// <summary>
        /// insert instance
        /// </summary>
        /// <param name="entity">instance</param>
        /// <returns>ID(primary key)</returns>
        object Save(T entity);

        /// <summary>
        /// modify instance
        /// </summary>
        /// <param name="entity">instance</param>
        void Update(T entity);

        /// <summary>
        /// insert or modify instance
        /// </summary>
        /// <param name="entity">instance</param>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// delete instance
        /// </summary>
        /// <param name="id">ID(primary key)</param>
        void Delete(object id);

        /// <summary>
        /// delete instances
        /// </summary>
        /// <param name="idList">ID collection(primary key collection)</param>
        void Delete(IList<object> idList);

        /// <summary>
        /// load all instances
        /// </summary>
        /// <returns>instance collection</returns>
        IQueryable<T> LoadAll();

        /// <summary>
        /// load instances by page
        /// </summary>
        /// <param name="count">number of all records</param>
        /// <param name="pageIndex">page number</param>
        /// <param name="pageSize">page size</param>
        /// <returns>collection</returns>
        IQueryable<T> LoadAllWithPage(out long count, int pageIndex, int pageSize);

        void ExecuteNonQuery(string sql);

        DataSet ExecuteDataSet(string sql);

        DataTable ExecuteDataTable(string sql);
    }
}
